// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1
import iapminimal.com 1.0
import Analytics 1.0
import com.nokia.symbian 1.1
import "inneractive"

Page {
    id: myscreen
    property string iapstate: "getProductData"

    Component.onCompleted: {
        // Initialize item with \e {Application key} and \e {Agent name} values.
        analyticsExample.initialize("2e15a80cf765630bf2b971d7a3c011f4", "iapminimal");
        // Start gathering analytics events.
        analyticsExample.start("iapminimalStarted");
    }

    // Create Analytics QML-item and set values for all available optional properties.
    Analytics {
        id: analyticsExample
        connectionTypePreference: Analytics.AnyConnection  // optional
        appLanguage: "Fi"                                  // optional
        minBundleSize: 20                                  // optional
        loggingEnabled: true                               // optional
    }

    TextArea {
        id: screenText
        readOnly : true
        text: qsTr("Clickme to see product data")
        anchors.centerIn: parent
    }

    MouseArea {
        anchors.fill: parent
        onClicked: {
            analyticsExample.logEvent("onclicked", myscreen.iapstate, Analytics.ActivityLogEvent);

            if(myscreen.iapstate === "exitApp"){
                analyticsExample.stop("stopAnalytic", Analytics.AppExit);
                //TODO: to emulate 20 seconds delay before application exit,
                // comment Qt.quit() and uncomment iap.closeIAP()
                Qt.quit();
                //iap.closeIAP();
            } else if(myscreen.iapstate === "getProductData"){
                iap.getProductData();
            } else if(myscreen.iapstate === "purchaseProduct"){
                iap.purchaseProduct();
            }
        }
    }

    IAPmin{
        id: iap
        onStatusBusy: screenText.text = "please wait..."
        onProductDataComplete: {
            screenText.text = data;
            myscreen.iapstate = "purchaseProduct";
        }
        onProductPurchaseComplete: {
            screenText.text = data;
            myscreen.iapstate = "exitApp";
        }
        onIapClosed: Qt.quit()
    }

    AdItem {
        parameters: params
        anchors.top: parent.top
        anchors.horizontalCenter: parent.horizontalCenter
        showText: false
    }

    AdItem {
        id: ad
        retryOnError: true
        reloadInterval: 100
        parameters: params
        anchors.bottom: parent.bottom
        anchors.horizontalCenter: parent.horizontalCenter
    }

    AdParameters {
        id: params
        applicationId: "IA_GameTest"
    }
}
